
Imports cmplib01


Public Class frmSelectOOB

    Private ptrGame As CampaignerGameData
    Private ptrDepZone As DeploymentZone
    Private _moveTypes() As String
    Private _actionCancelled As Boolean = False
    Private _selectedBG As BattlegroupChit

    Public Shadows Sub ShowDialog(ByRef game As CampaignerGameData, ByRef moveTypes As String(), ByRef DepZone As DeploymentZone)
        ptrGame = game
        ptrDepZone = DepZone
        _moveTypes = moveTypes
        ListOOB()
        ListPVs()
        MyBase.ShowDialog()
    End Sub

    Private Sub ListOOB()
        Try
            Dim bg As BattlegroupChit

            For Each bg In ptrGame.selectedFaction.OrderOfBattle
                Dim tv As New CampaignerItemTreeNode
                tv.Item = bg
                tv.Text = bg.Name
                tv.ItemType = CampaignerItem_cgd.Battlegroup
                tvwOOB.Nodes.Add(tv)
            Next

        Catch ex As Exception
            HandleException("frmSelectOOB.ListOOB", ex)
        End Try
    End Sub

    Private Sub ListPVs()
        Try
            lblFactionPV.Text = ptrGame.selectedFaction.FactionFreePoints
            lblDepZonePV.Text = ptrDepZone.MaxTotalDeploy
        Catch ex As Exception
            HandleException("frmSelectOOB.ListPVs", ex)
        End Try
    End Sub

    Private Sub tvwOOB_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwOOB.AfterSelect
        '// we list the units in this BG, by NUMBER of units? Like, 16 infantry, 4 tanks, etc
        Try

            If tvwOOB.SelectedNode Is Nothing Then Exit Sub

            Dim bg As BattlegroupChit = DirectCast(tvwOOB.SelectedNode, CampaignerItemTreeNode).Item

            lstUnits.Items.Clear()

            Dim un As ChitMember
            For Each un In bg.members
                lstUnits.Items.Add(un.Name)
            Next

            bg.CalculateProperties()

            '// show the properties of this mutha sukka
            picBG.BackgroundImage = bg.icon
            lblPointValue.Text = bg.deployedpointvalue
            lblMoveSpeed.Text = bg.MovementSpeed
            lblMType.Text = _moveTypes(bg.MovementClassID)

            _selectedBG = bg

        Catch ex As Exception
            HandleException("frmSelectOOB.tvwOOB_AfterSelect", ex)
        End Try
    End Sub

    Public Property SelectedBG() As BattlegroupChit
        Get
            Return _selectedBG
        End Get
        Set(ByVal value As BattlegroupChit)
            _selectedBG = value
        End Set
    End Property

    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        _actionCancelled = False
        Me.Hide()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        _actionCancelled = True
        Me.Hide()
    End Sub

    Public ReadOnly Property ActionCancelled() As Boolean
        Get
            Return _actionCancelled
        End Get
    End Property
End Class